home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Diamond Collection / The Diamond Collection (Software Vault)(Digital Impact).ISO / cdr49 / fgfx12.zip / EFFECTS.BAS next >
BASIC Source File  |  1995-02-14  |  20KB  |  597 lines

  1. '*****************************************************************************
  2. '                                                                            *
  3. '  EFFECTS.BAS                                                               *
  4. '                                                                            *
  5. '  This program demonstrates several methods of fading in an image from an   *
  6. '  off-screen video page using either Fastgraph or Fastgraph/Light.  The set *
  7. '  of routines provided herein are written for 320x200 graphics video modes, *
  8. '  but they could easily be extended to work in other resolutions.           *
  9. '                                                                            *
  10. '  The examples are by no means all inclusive.  Rather, their purpose is to  *
  11. '  illustrate a few methods of creating special effects with Fastgraph or    *
  12. '  Fastgraph/Light.                                                          *
  13. '                                                                            *
  14. '  To compile this program and link it with Fastgraph:                       *
  15. '                                                                            *
  16. '     BC /O EFFECTS;               (QuickBASIC 4.x)                          *
  17. '     LINK EFFECTS,,NUL,FGQB;                                                *
  18. '                                                                            *
  19. '     BC /Fs /O EFFECTS;           (BASIC PDS 7.x)                           *
  20. '     LINK EFFECTS,,NUL,FGQBX;                                               *
  21. '                                                                            *
  22. '     BC /O EFFECTS;               (Visual Basic for DOS)                    *
  23. '     LINK EFFECTS,,NUL,FGVBDOS;                                             *
  24. '                                                                            *
  25. '  This program also can be linked with Fastgraph/Light 4.0 if you replace   *
  26. '  the "FG" prefix on the above library file names with "FGL".               *
  27. '                                                                            *
  28. '  Fastgraph (tm) and Fastgraph/Light (tm) are graphics libraries published  *
  29. '  by Ted Gruber Software.  For more info, please call, write, or FAX.       *
  30. '                                                                            *
  31. '  Ted Gruber Software                           orders/info (702) 735-1980  *
  32. '  PO Box 13408                                          FAX (702) 735-4603  *
  33. '  Las Vegas, NV  89112                                  BBS (702) 796-7134  *
  34. '                                                                            *
  35. '*****************************************************************************
  36.  
  37. REM $INCLUDE: 'fastgraf.bi'
  38.  
  39. DEFINT A-Z
  40.  
  41. REM function declarations
  42.  
  43. DECLARE SUB Announce (Message$)
  44. DECLARE FUNCTION Irandom (Min, Max)
  45.  
  46. DECLARE SUB Curtain (Delay)
  47. DECLARE SUB DiagonalFade (Delay)
  48. DECLARE SUB HorizontalRandomFade (Delay)
  49. DECLARE SUB InwardTunnelEffect (Delay)
  50. DECLARE SUB OutwardTunnelEffect (Delay)
  51. DECLARE SUB SpiralDual (Delay)
  52. DECLARE SUB SpiralLayered (Delay)
  53. DECLARE SUB SpiralNormal (Delay)
  54. DECLARE SUB SplitScreen (Delay)
  55. DECLARE SUB Unveil (Delay)
  56. DECLARE SUB VenetianBlind (Delay)
  57.  
  58. REM global variables
  59.  
  60. COMMON SHARED Delay, ScrollDelay
  61.  
  62. REM start of main program
  63.  
  64. REM make sure a 320x200 color graphics mode is available
  65.  
  66. NewMode = FGbestmode(320,200,2)
  67. IF (NewMode < 0) OR (NewMode = 12) THEN
  68.    PRINT "This program requires a 320x200 color graphics mode."
  69.    STOP
  70. END IF
  71.  
  72. REM determine the number of delay units per half clock tick
  73.  
  74. Delay = FGmeasure / 2
  75.  
  76. REM initialize Fastgraph for the selected video mode
  77.  
  78. OldMode = FGgetmode
  79. FGsetmode NewMode
  80. Status = FGallocate(1)
  81.  
  82. REM display a packed pixel run file on a hidden page
  83.  
  84. FGsethpage 1
  85. FGsetpage 1
  86. FGmove 0, 199
  87. Status = FGshowppr("FG.PPR"+CHR$(0),320)
  88. FGsetpage 0
  89.  
  90. REM compute the number of delay units needed to make the text scroll
  91. REM down at the same rate, regardless of the CPU speed or video mode
  92.  
  93. Count = 0
  94. FGwaitfor 1
  95. StartTime& = FGgetclock
  96. DO
  97.    FGscroll 0, 319, 0, 7, 4, 1
  98.    Count = Count + 1
  99. LOOP WHILE (FGgetclock = StartTime&)
  100.  
  101. ScrollDelay = (Delay / 8) - (Delay * 2) / Count
  102. IF (ScrollDelay < 0) THEN ScrollDelay = 0
  103.  
  104. REM demonstrate the inward tunnel effect
  105.  
  106. Announce "inward tunnel effect"
  107. InwardTunnelEffect 0
  108. FGwaitfor 27
  109. Announce "inward tunnel effect with delay"
  110. InwardTunnelEffect Delay
  111. FGwaitfor 27
  112.  
  113. REM demonstrate the outward tunnel effect
  114.  
  115. Announce "outward tunnel effect"
  116. OutwardTunnelEffect 0
  117. FGwaitfor 27
  118. Announce "outward tunnel effect with delay"
  119. OutwardTunnelEffect Delay
  120. FGwaitfor 27
  121.  
  122. REM demonstrate the diagonal fade
  123.  
  124. Announce "diagonal fade"
  125. DiagonalFade 0
  126. FGwaitfor 27
  127. Announce "diagonal fade with delay"
  128. DiagonalFade Delay/2
  129. FGwaitfor 27
  130.  
  131. REM demonstrate the horizontal random fade
  132.  
  133. Announce "horizontal random fade"
  134. HorizontalRandomFade Delay
  135. FGwaitfor 27
  136.  
  137. REM demonstrate the curtain effect
  138.  
  139. Announce "curtain"
  140. Curtain Delay/8
  141. FGwaitfor 27
  142.  
  143. REM demonstrate the spiral effect
  144.  
  145. Announce "spiral"
  146. SpiralNormal Delay*2
  147. FGwaitfor 27
  148.  
  149. REM demonstrate the layered spiral effect
  150.  
  151. Announce "layered spiral"
  152. SpiralLayered Delay
  153. FGwaitfor 27
  154.  
  155. REM demonstrate the dual spiral effect
  156.  
  157. Announce "dual spiral"
  158. SpiralDual Delay/2
  159. FGwaitfor 27
  160.  
  161. REM demonstrate the split screen effect
  162.  
  163. Announce "split screen"
  164. SplitScreen Delay/2
  165. FGwaitfor 27
  166.  
  167. REM demonstrate the unveil effect
  168.  
  169. Announce "unveil"
  170. Unveil Delay/4
  171. FGwaitfor 27
  172.  
  173. REM demonstrate the "venetian blind" effect
  174.  
  175. Announce "venetian blind"
  176. VenetianBlind Delay
  177. FGwaitfor 27
  178.  
  179. REM restore the original video mode and screen attributes
  180.  
  181. Status = FGfreepage(1)
  182. FGsetmode OldMode
  183. FGreset
  184.  
  185. END
  186.  
  187. '*****************************************************************************
  188. '                                                                            *
  189. '  Announce                                                                  *
  190. '                                                                            *
  191. '  Display the name of the special effect we're about to see.                *
  192. '                                                                            *
  193. '*****************************************************************************
  194.  
  195. SUB Announce (Message$)
  196.  
  197. SHARED Delay, ScrollDelay
  198.  
  199. REM clear the screen
  200.  
  201. FGerase
  202.  
  203. REM display the specified message at the top row
  204.  
  205. FGsetcolor 10
  206. FGjustify 0, -1
  207. FGmove 160, 15
  208. FGfontsize 16
  209. FGprint Message$, LEN(Message$)
  210.  
  211. REM scroll the message to the center of the screen
  212.  
  213. FGsetcolor 0
  214.  
  215. FOR Y = 0 TO 95 STEP 4
  216.    FGscroll 0, 319, Y, Y+15, 4, 1
  217.    FGstall ScrollDelay
  218. NEXT
  219.  
  220. REM wait 1.5 seconds
  221.  
  222. FGwaitfor 27
  223.  
  224. END SUB
  225.  
  226. '*****************************************************************************
  227. '                                                                            *
  228. '  Irandom                                                                   *
  229. '                                                                            *
  230. '  Random number generator used in some of the effects.  It returns an       *
  231. '  integer between min and max inclusive.                                    *
  232. '                                                                            *
  233. '*****************************************************************************
  234.  
  235. FUNCTION Irandom (Min, Max)
  236.  
  237. Irandom = ((RND*32767) MOD (Max-Min+1)) + Min
  238.  
  239. END FUNCTION
  240.  
  241. '*****************************************************************************
  242. '                                                                            *
  243. '  Curtain                                                                   *
  244. '                                                                            *
  245. '  Reveal each row, one at a time, starting from the bottom and proceeding   *
  246. '  to the top.  This gives the effect of a curtain rising, hence the name.   *
  247. '                                                                            *
  248. '*****************************************************************************
  249.  
  250. SUB Curtain (Delay)
  251.  
  252. FOR Y = 199 TO 0 STEP -1
  253.    FGrestore 0, 319, Y, Y
  254.    FGstall Delay
  255. NEXT
  256.  
  257. END SUB
  258.  
  259. '*****************************************************************************
  260. '                                                                            *
  261. '  DiagonalFade                                                              *
  262. '                                                                            *
  263. '  This reveals the hidden page in two diagonal segments, separated by an    *
  264. '  imaginary line extending from the lower left corner to the upper right    *
  265. '  corner of the screen.  We start with the top line of the left segment and *
  266. '  the bottom line of the right segment, and continue until the entire       *
  267. '  screen is revealed.                                                       *
  268. '                                                                            *
  269. '*****************************************************************************
  270.  
  271. SUB DiagonalFade (Delay)
  272.  
  273. Xmin = 0
  274. Xmax = 319
  275. Ymin = 0
  276. Ymax = 199
  277.  
  278. WHILE (Xmax > 0)
  279.    FGrestore 0, Xmax, Ymin, Ymin+4
  280.    FGrestore Xmin, 319, Ymax-4, Ymax
  281.    FGstall Delay
  282.  
  283.    Xmin = Xmin + 8
  284.    Xmax = Xmax - 8
  285.    Ymin = Ymin + 5
  286.    Ymax = Ymax - 5
  287. WEND
  288.  
  289. END SUB
  290.  
  291. '*****************************************************************************
  292. '                                                                            *
  293. '  HorizontalRandomFade                                                      *
  294. '                                                                            *
  295. '  In this effect, the screen is divided into a series of two-pixel high     *
  296. '  rows.  Each row is revealed in random parts from left to right.  This     *
  297. '  process repeats 20 times, once for each row.  At the end, a call to the   *
  298. '  FGrestore routine guarantees that all rows are transferred.               *
  299. '                                                                            *
  300. '*****************************************************************************
  301.  
  302. SUB HorizontalRandomFade (Delay)
  303.  
  304. DIM Xpos(100)
  305.  
  306. FOR J = 0 TO 99
  307.    Xpos(J) = 0
  308. NEXT
  309.  
  310. FOR I = 1 TO 20
  311.    FOR J = 0 TO 99
  312.       Xmin = Xpos(J)
  313.       IF (Xmin < 320) THEN
  314.          Xmax = Xmin + Irandom(1,10) * 8
  315.          IF (Xmax > 320) THEN Xmax = 320
  316.          Y = J * 2
  317.          FGrestore Xmin, Xmax-1, Y, Y+1
  318.          Xpos(J) = Xmax
  319.       END IF
  320.    NEXT
  321.    FGstall Delay
  322. NEXT
  323.  
  324. REM make sure we got them all
  325.  
  326. FGrestore 0, 319, 0, 199
  327.  
  328. END SUB
  329.  
  330. '*****************************************************************************
  331. '                                                                            *
  332. '  InwardTunnelEffect                                                        *
  333. '                                                                            *
  334. '  Starting at the screen edges, reveal the screen through a series of       *
  335. '  concentric hollow rectangles.                                             *
  336. '                                                                            *
  337. '*****************************************************************************
  338.  
  339. SUB InwardTunnelEffect (Delay)
  340.  
  341. Xmin = 0
  342. Xmax = 319
  343. Ymin = 0
  344. Ymax = 199
  345.  
  346. WHILE (Xmin < Xmax)
  347.    FGrestore 0, 319, Ymin, Ymin+4
  348.    FGrestore Xmax-7, Xmax, 0, 199
  349.    FGrestore 0, 319, Ymax-4, Ymax
  350.    FGrestore Xmin, Xmin+7, 0, 199
  351.    FGstall Delay
  352.  
  353.    Xmin = Xmin + 8
  354.    Xmax = Xmax - 8
  355.    Ymin = Ymin + 5
  356.    Ymax = Ymax - 5
  357. WEND
  358.  
  359. END SUB
  360.  
  361. '*****************************************************************************
  362. '                                                                            *
  363. '  OutwardTunnelEffect                                                       *
  364. '                                                                            *
  365. '  Starting at the screen center, reveal the screen through a series of      *
  366. '  concentric hollow rectangles.                                             *
  367. '                                                                            *
  368. '*****************************************************************************
  369.  
  370. SUB OutwardTunnelEffect (Delay)
  371.  
  372. Xmin = 152
  373. Xmax = 167
  374. Ymin = 95
  375. Ymax = 104
  376.  
  377. WHILE (Xmin >= 0)
  378.    FGrestore Xmin, Xmax, Ymin, Ymin+5
  379.    FGrestore Xmax-7, Xmax, Ymin, Ymax
  380.    FGrestore Xmin, Xmax, Ymax-4, Ymax
  381.    FGrestore Xmin, Xmin+7, Ymin, Ymax
  382.    FGstall Delay
  383.  
  384.    Xmin = Xmin - 8
  385.    Xmax = Xmax + 8
  386.    Ymin = Ymin - 5
  387.    Ymax = Ymax + 5
  388. WEND
  389.  
  390. END SUB
  391.  
  392. '*****************************************************************************
  393. '                                                                            *
  394. '  SpiralDual                                                                *
  395. '                                                                            *
  396. '  In this effect, we reveal the screen through two spirals.  One spiral     *
  397. '  emanates clockwise from the screen edges to the screen center, while the  *
  398. '  other emanates counterclockwise from the center to the screen edges.      *
  399. '                                                                            *
  400. '*****************************************************************************
  401.  
  402. SUB SpiralDual (Delay)
  403.  
  404. XminOuter = 0
  405. XmaxOuter = 319
  406. YminOuter = 0
  407. YmaxOuter = 199
  408.  
  409. XminInner = 152
  410. XmaxInner = 167
  411. YminInner = 95
  412. YmaxInner = 104
  413.  
  414. WHILE (XminOuter < XminInner)
  415.    FGrestore XminOuter, XmaxOuter, YminOuter, YminOuter+4
  416.    FGstall Delay
  417.    FGrestore XminInner, XmaxInner, YmaxInner-4, YmaxInner
  418.    FGstall Delay
  419.    FGrestore XmaxOuter-7, XmaxOuter, YminOuter, YmaxOuter
  420.    FGstall Delay
  421.    FGrestore XmaxInner+1, XmaxInner+8, YminInner, YmaxInner
  422.    FGstall Delay
  423.    FGrestore XminOuter, XmaxOuter, YmaxOuter-4, YmaxOuter
  424.    FGstall Delay
  425.    FGrestore XminInner-8, XmaxInner, YminInner, YminInner+4
  426.    FGstall Delay
  427.    FGrestore XminOuter, XminOuter+7, YminOuter, YmaxOuter
  428.    FGstall Delay
  429.    FGrestore XminInner-8, XminInner-1, YminInner, YmaxInner+5
  430.    FGstall Delay
  431.  
  432.    XminOuter = XminOuter + 8
  433.    XmaxOuter = XmaxOuter - 8
  434.    YminOuter = YminOuter + 5
  435.    YmaxOuter = YmaxOuter - 5
  436.  
  437.    XminInner = XminInner - 8
  438.    XmaxInner = XmaxInner + 8
  439.    YminInner = YminInner - 5
  440.    YmaxInner = YmaxInner + 5
  441. WEND
  442.  
  443. END SUB
  444.  
  445. '*****************************************************************************
  446. '                                                                            *
  447. '  SpiralLayered                                                             *
  448. '                                                                            *
  449. '  This effect is similar to the normal spiral.  Instead of revealing the    *
  450. '  screen in one iteration, this effect does so in four iterations (layers), *
  451. '  each moving more toward the screen center.                                *
  452. '                                                                            *
  453. '*****************************************************************************
  454.  
  455. SUB SpiralLayered (Delay)
  456.  
  457. FOR I = 0 TO 3
  458.    Xmin = I * 8
  459.    Xmax = 319 - Xmin
  460.    Ymin = I * 5
  461.    Ymax = 199 - Ymin
  462.  
  463.    WHILE (Xmin < Xmax)
  464.       FGrestore Xmin, Xmax, Ymin, Ymin+4
  465.       FGstall Delay
  466.       FGrestore Xmax-7, Xmax, Ymin, Ymax
  467.       FGstall Delay
  468.       FGrestore Xmin, Xmax, Ymax-4, Ymax
  469.       FGstall Delay
  470.       FGrestore Xmin, Xmin+7, Ymin, Ymax
  471.       FGstall Delay
  472.  
  473.       Xmin = Xmin + 32
  474.       Xmax = Xmax - 32
  475.       Ymin = Ymin + 20
  476.       Ymax = Ymax - 20
  477.    WEND
  478. NEXT
  479.  
  480. END SUB
  481.  
  482. '*****************************************************************************
  483. '                                                                            *
  484. '  SpiralNormal                                                              *
  485. '                                                                            *
  486. '  This is a spiral effect in which we reveal the screen as a series of      *
  487. '  rectangles, emanating from the screen edges and proceeding clockwise to   *
  488. '  the center of the screen.                                                 *
  489. '                                                                            *
  490. '*****************************************************************************
  491.  
  492. SUB SpiralNormal (Delay)
  493.  
  494. Xmin = 0
  495. Xmax = 319
  496. Ymin = 0
  497. Ymax = 199
  498.  
  499. WHILE (Xmin < Xmax)
  500.    FGrestore Xmin, Xmax, Ymin, Ymin+19
  501.    FGstall Delay
  502.    FGrestore Xmax-31, Xmax, Ymin, Ymax
  503.    FGstall Delay
  504.    FGrestore Xmin, Xmax, Ymax-19, Ymax
  505.    FGstall Delay
  506.    FGrestore Xmin, Xmin+31, Ymin, Ymax
  507.    FGstall Delay
  508.  
  509.    Xmin = Xmin + 32
  510.    Xmax = Xmax - 32
  511.    Ymin = Ymin + 20
  512.    Ymax = Ymax - 20
  513. WEND
  514.  
  515. END SUB
  516.  
  517. '*****************************************************************************
  518. '                                                                            *
  519. '  SplitScreen                                                               *
  520. '                                                                            *
  521. '  Reveal the top half of from left to right while revealing the bottom half *
  522. '  from right to left.                                                       *
  523. '                                                                            *
  524. '*****************************************************************************
  525.  
  526. SUB SplitScreen (Delay)
  527.  
  528. Xmin = 0
  529. Xmax = 319
  530.  
  531. WHILE (Xmax > 0)
  532.    FGrestore Xmin, Xmin+7, 0, 99
  533.    FGrestore Xmax-7, Xmax, 100, 199
  534.    FGstall Delay
  535.    Xmin = Xmin + 8
  536.    Xmax = Xmax - 8
  537. WEND
  538.  
  539. END SUB
  540.  
  541. '*****************************************************************************
  542. '                                                                            *
  543. '  Unveil                                                                    *
  544. '                                                                            *
  545. '  Starting at the center, reveal the screen in small horizontal increments  *
  546. '  until we reach the left and right edges.                                  *
  547. '                                                                            *
  548. '*****************************************************************************
  549.  
  550. SUB Unveil (Delay)
  551.  
  552. Xmin = 152
  553. Xmax = 167
  554.  
  555. WHILE (Xmin >= 0)
  556.    FGrestore Xmin, Xmin+7, 0, 199
  557.    FGrestore Xmax-7, Xmax, 0, 199
  558.    FGstall Delay
  559.    Xmin = Xmin - 8
  560.    Xmax = Xmax + 8
  561. WEND
  562.  
  563. END SUB
  564.  
  565. '*****************************************************************************
  566. '                                                                            *
  567. '  VenetianBlind                                                             *
  568. '                                                                            *
  569. '  Reveal the screen in four iterations, each revealing every fourth row.    *
  570. '  The effect produced resembles opening a Venetian blind.                   *
  571. '                                                                            *
  572. '*****************************************************************************
  573.  
  574. SUB VenetianBlind (Delay)
  575.  
  576. FOR Y = 0 TO 199 STEP 4
  577.    FGrestore 0, 319, Y, Y
  578. NEXT
  579. FGstall Delay
  580.  
  581. FOR Y = 1 TO 199 STEP 4
  582.    FGrestore 0, 319, Y, Y
  583. NEXT
  584. FGstall Delay
  585.  
  586. FOR Y = 2 TO 199 STEP 4
  587.    FGrestore 0, 319, Y, Y
  588. NEXT
  589. FGstall Delay
  590.  
  591. FOR Y = 3 TO 199 STEP 4
  592.    FGrestore 0, 319, Y, Y
  593. NEXT
  594. FGstall Delay
  595.  
  596. END SUB
  597.